// 基于 SnowLang Project (https://gitee.com/jcnc-org/snow) 的衍生作品
// 原始版权归属: Copyright © 2025 Ke Xu (Luke)
// 本实现版权归属: Copyright © 2025 Sany
// 遵循 Apache License 2.0 授权
package execution

import (
	"gitee.com/xntk2381/cc/vm/io"
	"gitee.com/xntk2381/cc/vm/utils"
)

/**
 * Command Loader (CommandLoader)
 * <p>
 * This class is used to load instructions from a specified file path. It reads instruction data from the file
 * using {@link FileIOUtils}, and returns a list of instructions. If the file reading fails or the instruction list is empty,
 * an error log will be recorded using {@link LoggingUtils}.
 * </p>
 */
type commandLoader struct{}

/**
 * Default constructor for creating an instance of CommandLoader.
 * This constructor is empty as no specific initialization is required.
 */
func NewCommandLoader() *commandLoader {
	return &commandLoader{}
}

var CommandLoader = NewCommandLoader()

/**
 * Loads instructions from a file.
 * <p>
 * This method loads instructions from the given file path and returns them as a list. If the instruction reading fails or the list is empty,
 * an error log will be recorded and an empty instruction list will be returned.
 * </p>
 *
 * @param filePath The file path pointing to the file containing the instructions.
 * @return A list of instructions. If reading fails, an empty list will be returned.
 */
func (l *commandLoader) LoadInstructions(filePath string) []string {
	instructions := io.ReadInstructionsFromFile(filePath)

	if len(instructions) == 0 {
		utils.LogError("Failed to read instructions or the instruction list is empty")
	}

	return instructions
}
